package huoye.shops.huoye.operation.adapter;

import android.content.Context;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.codeideology.android.utils.StringUtils;
import com.codeideology.android.widget.recycler.RecyclerViewAdapter;

import butterknife.BindView;
import huoye.shops.R;
import huoye.shops.base.APIUrls;
import huoye.shops.common.model.OssImageData;
import huoye.shops.huoye.operation.model.EventOddPrizeList;
import huoye.shops.widget.RoundImageView;


/**
 * Created by uesr on 2018/8/10.
 */

public class SharePondAdapter extends RecyclerViewAdapter<SharePondAdapter.ViewHolder,EventOddPrizeList> {




    private String type;
    public SharePondAdapter(Context context, String eventType) {
        super(context, R.layout.item_take_share_set);
        this.type = eventType;
    }

    @Override
    protected ViewHolder initViewHolder(View view, int i) {

        return new ViewHolder(view);
    }

    @Override
    protected void bindView(ViewHolder holder,EventOddPrizeList eventOddPrizeList, int i) {


        String beginNum = eventOddPrizeList.getBeginNum();
        String endNum = eventOddPrizeList.getEndNum();

        //等于1 为共享奖池。 等于二为全民猜猜乐
        if(type.equals("1")){
            holder.tvWinning.setText(beginNum+"%～"+endNum+"%");
        }else {
            holder.tvWinning.setText("冠名奖品");
            holder.tvWinningHint.setVisibility(View.GONE);
        }


        holder.ivAddImage.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                listener.onAddPrizeClick(eventOddPrizeList,i);
            }
        });

        String getNum = eventOddPrizeList.getGetNum();
        String prizeNum = eventOddPrizeList.getPrizeNum();


        Integer intPrizeNum = Integer.valueOf(prizeNum);
        Integer intGetNum = Integer.valueOf(getNum);



        holder.tvPrizeNumber.setText(intPrizeNum+"/"+(intPrizeNum - intGetNum));

        if(StringUtils.isNotEmpty(eventOddPrizeList.getPrizeImg())){
            if(getContext() != null){
                Glide.with(getContext() )
                        .load(APIUrls.COMMON_CONFIG.TYPE_COMMON_ALIYUN+eventOddPrizeList.getPrizeImg())
                        .dontAnimate()
                        .placeholder(R.mipmap.ic_wait_logo)
                        .error(R.mipmap.ic_error)
                        .into(holder.ivAddImage);
            }
        }



    }


    public class ViewHolder extends RecyclerViewAdapter.ViewHolder {

        @BindView(R.id.item_take_share_set_tv_winning)
        TextView tvWinning;
        @BindView(R.id.item_take_share_set_tv_winning_hint)
        TextView tvWinningHint;
        @BindView(R.id.item_take_share_set_tv_prize_number)
        TextView tvPrizeNumber;

        @BindView(R.id.item_take_share_set_iv_add_image)
        ImageView ivAddImage;
  ;


        public ViewHolder(View itemView) {
            super(itemView);
        }
    }



    public void setOnSharePondListener(OnSharePondListener onSharePondListener) {
        this.listener = onSharePondListener;
    }

    private OnSharePondListener listener;

    public interface OnSharePondListener {

        void onAddPrizeClick(EventOddPrizeList eventOddPrizeList,int i);


    }

}
